<template>
	<view class="newtodo-wrapper">
		<input type="text" class="a" v-model="note" placeholder="请输入待办内容">
		<view class="newtodo-click">
			<view class="bar">
			</view>
			<button @click="commitNote">确认</button>
			<button class="close" @click="close">取消</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				note: ''
			}
		},
		computed: {
			todolist() {
				return this.$store.state.todolist
			}
		},
		inject: ['toggle', 'setToggle'],
		methods: {
			commitNote() {
				this.$store.commit('addTodolist', this.note)
				this.setToggle()
				uni.showToast({
					title: '创建成功'
				})
				this.note = ''
			},
			close() {
				this.setToggle()
			}
		}
	}
</script>

<style lang="scss">
	.newtodo-wrapper {
		margin-top: 5px;
		padding: 10px 0px;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		>input {
			border: 1px solid #a1a0a0;
			padding: 5px;
			border-radius: 5px;
		}

		>.newtodo-click {
			display: flex;
			width: 100%;
			justify-content: flex-end;
			margin-top: 10px;

			>.bar {
				flex-grow: 1;
			}

			>button {
				background: rgb(59, 85, 71);
				color: rgb(221, 216, 216);
				padding: 5px 15px;
				border-radius: 5px;
				border: 1px solid #a1a0a0;
				box-shadow: 1px 1px 2px 2px rgb(223, 220, 220);
			}

			>.close {
				margin: 0px 20px;
				background: rgb(132, 134, 133);
			}
		}

	}
</style>
